$(function() {
	/*心理自测详情*/
	initgetEvaluatingQuestion();
	function initgetEvaluatingQuestion(){
		var EvaluatingId =utilModule.getQueryString("id");
		var param = {"EvaluatingId":EvaluatingId};

		patientTestmodule.getEvaluatingQuestion(param,callBack);
		function callBack(data){
			var id =utilModule.getQueryString("qid");
			templateText(id,data);
		}
		var status = sessionStorage.getItem("status"); 
		if(status != 1){
			window.location.href="./patient-test.html";
		}
	}
	function templateText(id,data){
		var abcdef=new Array("A","B","C","D","E","F");
		for (i in data) {
			if(i ==id){
				var k =parseInt(i)+1;
				var html ='<div class="patient-question font3"><span><font>'+k+'</font>/<font>'+data.length+'</font></span>'+data[i].text+'</div><div class="patient-answer font3"><ul>';
				var html2 = '</ul></div><div class="inscribe font"><span>本量表由馨语医疗 APP 提供</span></div>';
				for (j in data[i].evaluatingAnswerList) {
					if(id ==data.length-1){
						html +=	'<li data-id ="'+k+'" data-status ="1" data-qid ="'+data[i].id+'" data-score="'+data[i].evaluatingAnswerList[j].score+'">'+
				    				'<span>'+abcdef[j]+'</span>'+
				    				'<div>'+data[i].evaluatingAnswerList[j].text+'</div>'+
				    			'</li>';
					}else{
						html +=	'<li data-id ="'+k+'" data-status ="0" data-qid ="'+data[i].id+'" data-score="'+data[i].evaluatingAnswerList[j].score+'">'+
				    				'<span>'+abcdef[j]+'</span>'+
				    				'<div>'+data[i].evaluatingAnswerList[j].text+'</div>'+
				    			'</li>';
			    	}
				}
				html = html+html2;
				$("body").empty();
				$("body").prepend(html);
				
			}
		}
		
	}
	/*绑定选择题目的按钮*/
	$("li").on("click",function(){
		var status =$(this).data("status");
		var id =$(this).data("qid");
		var score=parseInt($(this).data("score"));
		//alert(score);
		var qid=$(this).data("id");
		if(status ==1){
			var url =window.location.href;
			url = url.split("&qid")[0];
			url = url.split("&qscore");
			for (i in url) {
				if(i>0){
					//console.log(url[i]);
					score += parseInt(url[i].split("=")[1]);
					//console.log(score);
				}
			}
			console.log(score);
			
			window.location.href="./patient-detail.html?id="+id+"&score="+score;
			
		}else{
			var url =window.location.href;
			url = url.split("qid")[0]+"qscore"+qid+"="+score+"&qid="+qid;
			
			window.location.href=url;	
		}
		
		
	});
	
	
	
	

}); 